package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.vo.account.AccountLockResultVo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account/userAccount")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountApiController {

	@Autowired
	private UserAccountService userAccountService;
	/**
	 * 获取账户余额
	 * @return
	 */
	@TsLogin
	@Operation(summary = "获取账户余额")
	@GetMapping("getAvailableAmount")
	public Result getAvailableAmount(){
		//	需要获取用户Id
		Long userId = AuthContextHolder.getUserId();
		//	调用服务层方法.
		BigDecimal availableAmount = userAccountService.getAvailableAmount(userId);
		//	返回数据
		return Result.ok(availableAmount);
	}

	/**
	 * 检查锁定账户金额
	 * @param accountLockVo
	 * @return
	 */
	@TsLogin
	@Operation(summary = "检查与锁定账户金额")
	@PostMapping("checkAndLock")
	public Result<AccountLockResultVo> checkAndLock(@RequestBody AccountLockVo accountLockVo){
		//	调用服务层方法
		return this.userAccountService.checkAndLock(accountLockVo);
	}
}

